<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class BaseController extends Controller
{
    public function login(Request $request){
    	// 如果是get请求,返回login
    	if($request->isMethod('get')){
			return  view('login');
		}
		// 验证登陆
    	$username=$request->input('username');
    	$password=$request->input('password');
		$num = DB::table('user')->where('username',$username)->value('pwd');
		if($num){
			if($num==md5($password)){
				session(['key' => $username]);
				return redirect('admin/index');
			}else{
				echo '账号密码错误！';
			}
		}else{
			echo '账号错误，模板暂时没做。';
		}
    }
    // 登出
    public function logout(Request $request){
    	$request->session()->forget('key');
		return redirect('admin/index');
    }
}
